/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

#ifndef _WORKERNETWORK_TEST_HPP_
#define _WORKERNETWORK_TEST_HPP_

#include <iostream>
#include <string>

#include "worker_network.hpp"

namespace middleware {
//-----------------------------------------------------------------------------
// Definitions
/*!
 * Test function for Adress
 */
void WorkerNetworkTest();
//-----------------------------------------------------------------------------
// Implementations
void WorkerNetworkTest(){
	Address ad1("192.168.1.1",11111);
	Address ad2("192.168.1.2",22222);

	std::vector<Address> adrs;
	adrs.push_back(ad1);
	adrs.push_back(ad2);

	/*!
	 * Testing construct.
	 */
	WorkerNetwork wn1;
	WorkerNetwork wn2;
	WorkerNetwork wnCopy;

	/*!
	 * Testing copy construct.
	 */
	WorkerNetwork wn3(wn2);
	wnCopy = wn3;

	/*!
	 * Testing push_back.
	 */
	wn1.push_back(ad1);
	wn1.push_back(ad2);
	wn2.push_back(ad1);
	wn2.push_back(ad2);


	/*!
	 * Testing size
	 */
	cout << "Size: " << wn1.size() << endl;

	/*!
	 * Testing clear & empty
	 */
	cout << "wn2 size: " << wn2.size() << endl;
	cout << "start clearing wn2..." << endl;
	wn2.clear();
	cout << "If printing 1, clear() & empty() methods are OK ---> "
			<< wn2.empty() << endl;

	/*!
	 * Testing iterators.
	 */
	cout << "Testing Iterators..." << std::endl;
	WorkerNetwork::AddressCollectionConstIterator it;
	for(it=wn1.begin(); it<wn1.end(); it++) {
		cout << "-" << it->get_port() << std::endl;
	}

	/*!
	 * Testing assign.
	 */
	wnCopy.assign((WorkerNetwork::AddressCollectionConstIterator)(adrs.begin()),
			(WorkerNetwork::AddressCollectionConstIterator)(adrs.end()));
}
}
#endif
